package br.com.mmm.javacenter.framework.reflection.injectors;

import br.com.mmm.javacenter.framework.annotations.InjectorComponent;
import br.com.mmm.javacenter.framework.dao.RepositoryBase;
import br.com.mmm.javacenter.framework.entity.TipoStatus;
import br.com.mmm.javacenter.framework.reflection.ReflectionFacade;

@InjectorComponent({
	TipoStatus.class
})
public class TipoStatusInjector implements Injector{

	private RepositoryBase<TipoStatus> repository;
	
	public RepositoryBase<TipoStatus> getRepository() {
		return repository;
	}

	public void setRepository(RepositoryBase<TipoStatus> repository) {
		this.repository = repository;
	}

	public void inject(ReflectionFacade rf, String field, Object value) {
		TipoStatus tipoStatus = new TipoStatus();
		if(value.toString().contains("-")){
			String[] split = value.toString().split("-");
			tipoStatus.setId(Long.parseLong(split[0]));
			tipoStatus.setDescricao(split[1]);
		}else{
			tipoStatus.setId(Long.parseLong(value.toString()));
		}
		rf.set(field, repository.consultaPorCodigo(tipoStatus));
	}
	
}
